package com.tedu.day01.oop;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class ColorJPanel extends JPanel implements Runnable {
	int time=1;
	Thread t;
	public ColorJPanel(){
		setBackground(Color.BLACK);
		t=new 	Thread(this);
		t.start();
	}
	public void paint(Graphics g) {
		super.paint(g);
		
	}
	
	public void run(){
		while(true){
			time++;
			if(time%3==1){this.setBackground(Color.BLACK);
				
			}
			
			else if(time%3==2){
				this.setBackground(Color.red);
					
			}
			
			else if(time%3==3){
				this.setBackground(Color.green);
				
			}
			
			else if(time%3==4){
				this.setBackground(Color.pink);
				
			}else{
				setBackground(Color.YELLOW);
			}
		repaint();
		try{
			Thread.sleep(1000);
		} catch(InterruptedException e){
			e.printStackTrace();
		}
			
			
		}
	}

}
